package genalgoritm.viewer;

import genalgoritm.count.RealChromosome;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;

public class PersonLabelProvider extends LabelProvider implements
		ITableLabelProvider {
	public static String[] COLS = {"x", "s", "f(x)" };
	public static Integer[] WIDTHS = {100, 100, 100 };
	
	@Override
	public Image getColumnImage(Object element, int columnIndex) {
		return null;
	}

	@Override
	public String getColumnText(Object element, int columnIndex) {
		RealChromosome person = (RealChromosome) element;
		switch (columnIndex) {
		case 0:
			return String.valueOf(person.getX());
		case 1:
			return person.getChr();
		case 2:
			Double fitness = person.fitness();
			String str = fitness.toString();
			Integer i = (str.length() < (str.indexOf(".") + 4)) ? str.length()
					: str.indexOf(".") + 4;
			Integer endIndex = (str.indexOf("E") == -1) ? i : str.length();
			return str.substring(0, endIndex);
		default:
			throw new RuntimeException("Should not happen");
		}
	}
}
